package com.huii.huiiplayer.activity;

import services.MyPlayService;
import services.MyPlayService.MyBinder;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.Menu;
import app.BaseActivity;

import com.huii.huiiplayer.R;

public class MainActivity extends BaseActivity {

	private MyPlayService service;
	private ServiceConnection sConnection;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub

	}

	@Override
	public void initData() {
		// 绑定服务,执行对MyPlayService的操作
		bindMyPlayService();

	}

	private void bindMyPlayService() {
		// TODO Auto-generated method stub

		sConnection = new ServiceConnection() {

			@Override
			public void onServiceDisconnected(ComponentName name) {
				// 服务对象置空
				MainActivity.this.service = null;
			}

			@Override
			public void onServiceConnected(ComponentName name, IBinder service) {
				// 获得服务对象
				MainActivity.this.service = ((MyBinder) service).getService();
			}
		};
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
